# -*- coding: utf-8 -*-
"""
Author:duan
Date: 2021/3/15 22:36
"""
from oslo_config import cfg
import oslo_messaging

opts = [
    cfg.StrOpt('url', default='helloworld'),
]

CONF = cfg.CONF
CONF.register_opts(opts)

CONF(default_config_files=['my.conf'])

transport_url = CONF.url

transport = oslo_messaging.get_transport(cfg.CONF, transport_url)
target = oslo_messaging.Target(topic='test')
client = oslo_messaging.RPCClient(transport, target)
r = client.call({}, 'add', a=2, b=3)
print('result :', r)

# Target对象的属性在RPCClient对象构造之后，还可以通过prepare()方法修改，
# 可以修改的属性包括exchange,topic,namespace,version，server,fanout和retry。
# 修改后的target属性只在这个prepare()方法返回的对象中有效。

cctxt = client.prepare(version='1.0')
r_two = cctxt.call({}, 'add', a=12, b=13)
print('result_two :', r_two)
